<template>
    <div class="list_page_div">
        <page-list :loading="loading" :table-config="tableConfig" :data-list="dataList" :height="height" show-index
                   show-page :total="total" :currentPage="param.pageNum" :pageSize="param.pageSize" @currentChange="handleCurrentChange"
                   show-operate operate-width="200">
            <template #searchArea>
                <el-input v-model="param.noticeTitle" clearable placeholder="公告标题" style="width: 200px;"></el-input>
                <el-input v-model="param.noticeContent" clearable placeholder="公告内容" style="width: 200px;"></el-input>
                <el-button type="primary" @click="searchList">查询</el-button>
                <el-button type="primary" @click="resetData">重置</el-button>
                <el-button type="primary" @click="editData()">新增</el-button>
            </template>

            <template #item_noticeFlag="scope">
                {{ $common.getDicName('noticeFile', scope.row.noticeFlag) }}
            </template>

            <template #operateContent="scope">
                <el-button type="text" @click="editData(scope.row.id)" v-if="scope.row.noticeFlag===1">编辑</el-button>
                <el-popconfirm title="是否确定删除当前数据？" @confirm="delData(scope.row.id)" v-if="scope.row.noticeFlag===1">
                    <el-button slot="reference" type="text">删除</el-button>
                </el-popconfirm>
                <el-button type="text" @click="releaseData(scope.row.id)" v-if="scope.row.noticeFlag===1">发布</el-button>
                <el-button type="text" @click="revokeData(scope.row.id)" v-if="scope.row.noticeFlag===2">撤回</el-button>
            </template>
        </page-list>
        <!--编辑-->
        <notice-edit :visible.sync="showEdit" :id="id" @refreshList="searchList"></notice-edit>
    </div>
</template>

<script>
import PageList from "@/components/grid/pageList.vue";
import NoticeEdit from "./component/noticeEdit.vue";

export default {
    name: "noticeList",
    components: {NoticeEdit, PageList},
    data() {
        return {
            height: 300,
            loading: false,
            showEdit: false,
            
            id: '',
            tableConfig: [
                {label: "公告标题", prop: "noticeCode", width: 220},
                {label: "公告标题", prop: "noticeTitle", minWidth: 300},
				{label: "开始日期", prop: "beginDate", width: 120},
				{label: "结束日期", prop: "endDate", width: 120},
                {label: "公告状态", prop: "noticeFlag", width: 80, slot: true},
                {label: "创建时间", prop: "createTime", width: 200}
            ],
            dataList: [],
            total: 0,
            param: {
                noticeTitle: '',
                operateTime: '',
                field: 'create_time',
                order: 'desc',
                pageSize: 20,
                pageNum: 1,
            },
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.height = (document.body.offsetHeight - 185) + "px";
        })
        this.searchList();
    },
    methods: {
        handleCurrentChange(val) {
            this.param.pageNum = val;
            this.loading = true;
            this.searchList();
        },
        resetData() {
            this.param.noticeTitle = '';
            this.param.beginCreateTime = '';
            this.param.endCreateTime = '';
            this.param.pageNum = 1;
            this.searchList();
        },
        searchList() {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/systemNotice/getPageList", this.param).then(res => {
                this.total = res.data.total;
                this.dataList = res.data.rows;
            }).finally(() => {
                this.loading = false;
            })
        },
        editData(id) {
            this.id = id;
            this.showEdit = true;
        },
        delData(id) {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/systemNotice/delete/" + id).then(res => {
                this.searchList();
                this.$message.success(res.message);
            }).finally(() => {
                this.loading = false;
            })
        },
        releaseData(id) {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/systemNotice/release/" + id).then(res => {
                this.searchList();
                this.$message.success(res.message);
            }).finally(() => {
                this.loading = false;
            })
        },
        revokeData(id) {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/systemNotice/revoke/" + id).then(res => {
                this.searchList();
                this.$message.success(res.message);
            }).finally(() => {
                this.loading = false;
            })
        },
		editDetail(id) {
			this.id = id;
			this.showDetail = true;
		},
    }
}
</script>

<style scoped>

</style>